// pages/search/search.js
import request from '../../utils/request.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword: '',
    courses: [],
    levelArr: ['', '初级', '中级', '高级']
  },

  getKeyword(e) {
    this.setData({
      keyword: e.detail.value
    })
  },

  // 取消搜索
  cancel() {
    this.setData({
      keyword: ''
    })
  },

  /**
   * 根据关键字搜索课程
   */
  async getCoursesData() {
    let keyword = this.data.keyword
    if (!keyword){
      return
    }
    const result = await request({
      url: '/course/search', data: {
        name: this.data.keyword
      }
    })

    this.setData({
      courses: result.message
    })
  }
})